
package CtrlLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 * @version 12/22/2011
 * @author Gruppe 4
 */

public class CtrlMachine 
{
    private IFDBMachine dbMac;
    

    /**
     * Constructor for class CtrlMachine
     */
    public CtrlMachine()
    {
        dbMac = new DBMachine();
    }
    
    /**
     * Method to find all machines
     * @param ()
     * @return returns an ArrayList<Machine>
     */
    public ArrayList<Machine> getAllMachines(boolean retrieveAssociation)
    {
      return dbMac.getAllMachines();
    }
    
    /**
     * Method to find a machine with a unique id
     * @param machineId int machineId the id for the machine
     * @return returns a Machine object
     */
    public Machine findMachine(int machineId, boolean retrieveAssociation)
    {
        return dbMac.findMachine(machineId,true);
    }
    
    /**
     * Method to insert a new machine in the database
     * @param machine Object Machine the machine we want to insert in the database
     */
    public int insertMachine(String type, String name, String fuelType, String model, double hourPrice, String comment)
    {
        Machine mac = new Machine();
        mac.setName(name);
        mac.setType(type);
        mac.setFuelType(fuelType);
        mac.setModel(model);
        mac.setHourPrice(hourPrice);
        mac.setComment(comment);
           
        return dbMac.insertMachine(mac);
    }
    
    /**
     * Method to update a machine in the database
     * @param machineId int machineId the Id of the machine
     * @param type String type the type of machine
     * @param name String name the name of the machine
     * @param fuelType String fuelType the fuelType of the machine
     * @param model String model the model of the machine
     * @param hourPrice double hourPrice the hourPrice of the machine
     * @param comment String comment the comment on the machine
     * @return returns an int 1 if the method succedes and -1 if the method fails
     */
    public int updateMachine(int machineId, String type, String name, String fuelType, String model, double hourPrice, String comment)
      {
          Machine mac = new Machine();
          mac.setMachineId(machineId);
          mac.setType(type);
          mac.setName(name);
          mac.setFuelType(fuelType);
          mac.setModel(model);
          mac.setHourPrice(hourPrice);
          mac.setComment(comment);
         
          return  dbMac.updateMachine(mac);
      }
 
    /**
     * Method to delete a machine from the database
     * @param machineId int machineId the id of the machine
     */
    public void deleteMachine(int machineId )
      {
          dbMac.deleteMachine(machineId);          
      }
    
}
